package com.ibeeking.found.cop.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.cop.b.rest.service.IGroupService;
import com.ibeeking.found.cop.service.common.param.GroupParam;
import com.ibeeking.found.cop.service.common.query.GroupPageQuery;
import com.ibeeking.found.cop.service.common.query.GroupQuery;
import com.ibeeking.found.cop.service.common.vo.GroupVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName GroupController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/group/v1")
public class GroupController {

    @Resource
    private IGroupService groupServiceImpl;

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步客户群列表")
    @PostMapping(value = "/syncGroupList")
    public Integer syncEmployeeList() {
        return groupServiceImpl.syncGroupFromWx();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客户群列表")
    @PostMapping(value = "/list")
    public List<GroupVO> list(@RequestBody GroupQuery query) {
        return groupServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客户群分页列表")
    @PostMapping(value = "/pageList")
    public Page<GroupVO> pageList(@RequestBody GroupPageQuery pageQuery) {
        return groupServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加客户群")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) GroupParam param) {
        return groupServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改客户群")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) GroupParam param) {
        return groupServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改是否启用")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return groupServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看客户群详情")
    @GetMapping(value = "/view/{id}")
    public GroupVO view(@PathVariable("id") Long id) {
        return groupServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除客户群")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return groupServiceImpl.del(id);
    }

}
